﻿namespace TC
{
    public class Service : BTNode, IUpdate
    {
        public FlowOutput<BTNode> out0;

        public FlowOutput<FlowNode> start;
        public FlowOutput<FlowNode> stop;
        public FlowOutput<FlowNode> update;

        private Dispatcher startCalls;
        private Dispatcher stopCalls;
        private Dispatcher updateCalls;

        public override void OnCreate()
        {
            base.OnCreate();

            start = this.AddFlowOutPort<FlowNode>("start");
            stop = this.AddFlowOutPort<FlowNode>("stop");
            update = this.AddFlowOutPort<FlowNode>("update");
            
            out0 = this.AddFlowOutPort<BTNode>("Out");
        }

        public override void Execute(Dispatcher chain)
        {
            base.Execute(chain);

            startCalls.Call(start);
            chain.Call(out0);
        }

        public override void Stop()
        {
            base.Stop();

            stopCalls.Call(stop);
        }

        public void OnUpdate(float delta)
        {
            updateCalls.Call(update);
        }
    }
}
